<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include/header_css::header('操作权限-角色管理')"></head>
<body>
	<div id="dpLTE" class="container-fluid" v-cloak>
		<ul id="menuTree" class="ztree"></ul>
	</div>
	<div th:include="include/footer_js::footer"></div>
	<script type="text/javascript">

	var setting = {
		data : {
			simpleData : {
				enable : true,
				idKey : "id",
				pIdKey : "parentId",
				rootPId : 0
			},
			key : {
				url : "nourl"
			}
		},
		check:{
			enable:true,
			nocheckInherit:true
		}
	};
	var ztree;

	var vm = new Vue({
		el : '#dpLTE',
		data : {
			role : {}
		},
		methods : {
			getMenu : function(menuId) {
				$.get(host+'menu/query?_' + $.now(), function(r) {
					ztree = $.fn.zTree
							.init($("#menuTree"), setting, r.data);
					ztree.expandAll(true);
				})
			},
			setForm: function() {
				$.SetForm({
					url: host+'role/info',
                    data : {"id":vm.role.id},
			    	success: function(data) {
			    		vm.role = data;
			    		//勾选角色所拥有的菜单
		    			var menuIds = vm.role.menuIdList;
		    			for(var i=0; i<menuIds.length; i++) {
		    				var node = ztree.getNodeByParam("id", menuIds[i]);
		    				ztree.checkNode(node, true, false);
		    			}
			    	}
				});
			},
			acceptClick: function() {
				var nodes = ztree.getCheckedNodes(true);
				var menuIdList = new Array();
				for(var i=0; i<nodes.length; i++) {
					menuIdList.push(nodes[i].id);
				}
				vm.role.menuIdList = menuIdList;
				$.ConfirmForm({
			    	url: host+'role/menuAuthSave?_' + $.now(),
                    contentType : 'application/json',
                    param: vm.role,
			    	success: function(data) {
			    	}
			    });
			}
		},
		created : function() {
            $(".basePath").each(function () {
                host=$(this).val();
            });
			this.getMenu();
		}
	})
	</script>
</body>
</html>